
<template>
  <div class="record">
    <tab>
      <tab-item :selected="type === 0" @on-item-click="change(0)">{{$t('purchase')}}</tab-item>
      <tab-item :selected="type === 1" @on-item-click="change(1)">{{$t('sale')}}</tab-item>
    </tab>
    <!--<div class="wire"></div>-->
    <div class="list">
        <scroller
          :on-refresh="refresh"
          :on-infinite="infinite"
          :noDataText="$t('no more')"
          ref="myScroller"
        >
          <ul v-for="i in data">
            <li>
              <div class="left">
                <p class="p2"><span  v-if="type === 0">{{$t('buyer')}}</span><span v-else>{{$t('seller')}}</span>：{{i.user_id}}</p>
                <p class="p4">{{$t('num')}}：{{i.residue_cny}}</p>
              </div>
              <div class="right">
                <p class="p5">{{$t('no')}}：{{i.deal_sn}}</p>
                <p class="p3">{{i.create_time}}</p>
              </div>
            </li>
          </ul>
          <no-data :nomore=false v-if="showNodata"></no-data>
        </scroller>
    </div>
  </div>
</template>

<i18n>
  purchase:
    en: Purchase
    zh-CN: 购买
  sale:
    en: Sale
    zh-CN: 出售
  buyer:
    en: BuyerID
    zh-CN: 买家ID
  seller:
    en: SellerID
    zh-CN: 卖家ID
  num:
    en: Number
    zh-CN: 数量
  no:
    en: No.
    zh-CN: 单号
</i18n>

<script>
  import {Cell, Group, Tab, TabItem} from 'vux'
  import noData from '../../components/nodata'
  export default {
    name: 'index',
    components: {
      Cell,
      Group,
      Tab,
      TabItem,
      noData
    },
    data () {
      return {
        data: [],
        type: 0,
        page: 1,
        listRows: 20,
        showNodata: false,
        scrollLoading: true
      }
    },
    created () {
      this.init()
    },
    methods: {
      init () {
        this.getInfo()
      },
      refresh (done) {
        this.page = 1
        this.data = []
        this.getInfo(done)
      },
      infinite (done) {
        if (!this.scrollLoading) {
          this.getInfo(done)
        } else {
          this.$refs.myScroller.finishInfinite(true)
        }
      },
      change (num) {
        this.type = num
        this.data = []
        this.page = 1
        this.getInfo()
      },
      getInfo (done) {
        let vm = this
        this.scrollLoading = true
        let showLoding
        vm.page === 1 ? showLoding = true : showLoding = false
        this.post({
          url: `/api/index/alldeal`,
          showloading: showLoding,
          params: {
            token: localStorage.token,
            type: vm.type,
            listRows: vm.listRows,
            page: vm.page
          },
          success: (data) => {
            console.log(data)
            if (data.code === 0) {
              this.$vux.toast.show({
                text: `${data.msg}`,
                type: 'text'
              })
              vm.$refs.myScroller.finishInfinite(true)
              done()
            } else if (data.code === 1) {
              data.data.data.length === 0 ? vm.showNodata = true : vm.showNodata = false
              if (data.data.data.length === 0) {
                vm.scrollLoading = true
                vm.$refs.myScroller.finishInfinite(true)
              } else if (data.data.data.length === vm.listRows) {
                vm.data = vm.data.concat(data.data.data)
                vm.scrollLoading = false
                vm.page = vm.page + 1
                // vm.$refs.myScroller.finishInfinite(true)
              } else {
                vm.scrollLoading = true
                vm.data = vm.data.concat(data.data.data)
                vm.$refs.myScroller.finishInfinite(true)
              }
              done()
            }
          }
        })
      }
    }
  }
</script>

<style scoped>

  .record{
    font-size: 0.3rem;
    height: 100%;
  }
  .record h5{
    height: 0.9rem;
    line-height: 0.9rem;
    margin: 0;
    font-weight: normal;
    background-color: #537fbf;
    color: #fff;
    display: flex;
  }
  .record h5 a{
    font-size: 0.4rem;
    text-decoration: none;
    color: #fff;
    flex-grow: 1;
    margin-left: 0.4rem;
  }
  .record h5 span{
    flex-grow:2 ;
    padding-left: 1rem;
  }
  .nav-tab{
    display: flex;
    list-style: none;
    height: 1rem!important;
    margin: 0;
    line-height: 1rem;

  }
  .nav-tab li{
    flex-grow: 1;
    text-align: center;
  }
  .nav-tab li div{
    width: 1.8rem;
    margin: 0 auto;
  }

  .nav-tab li a{
    color: #666;
  }
  .nav-tab li a:hover{
    color: #7294c8;
  }
  .nav-tab li div:hover{
    border-bottom: 2px solid #7294c8;
  }
  .wire{
    height: 0.1rem;
    background-color: #fafafa;
  }
  .list {
    height: calc(100% - 44px);
    position: relative;
  }
  .list ul{
    border-bottom: 0.01rem solid #eeeeee;
  }
  .list li{
    display: flex;
  }
  .list .left{
    flex-grow: 1;
    padding-left: 0.4rem;
  }
  .list .right{
    flex-grow: 2;
    width: 2.5rem;
    text-align: right;
    padding-right: 0.4rem;
  }
  p{
    line-height: 0.7rem;
    font-size: 0.28rem;
  }
  .list .p3{
    font-size: 0.2rem;
    color: #999;
  }
  .list .p4{
    color: #537fbf;
    font-weight: 800;
  }
  .list .p5{
    color: #666666;
  }

</style>
